import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import orderRouter from '@/router/modules/order'
import configuration from '@/router/modules/configuration'
import warehouseRouter from '@/router/modules/warehouse'
import commodityRouter from '@/router/modules/commodity'
import userRouter from '@/router/modules/user'
import marketingRouter from '@/router/modules/marketing'
import financialRouter from '@/router/modules/financial'
import reportRouter from '@/router/modules/report'
import shopRouter from '@/router/modules/shop'
import kitchenRouter from '@/router/modules/kitchen'
import distributionRouter from '@/router/modules/distribution'
import globalRouter from '@/router/modules/global'
import tplusRouter from '@/router/modules/tplus'
import merchantRouter from '@/router/modules/merchant'
import supplierRouter from '@/router/modules/supplier'
import traceability from '@/router/modules/traceability'
import feedbackRouter from "@/router/modules/feedback"
import relationRouter from "@/router/modules/relation"
import priceRouter from "@/router/modules/price"
import menuRouter from "@/router/modules/menu"
import sampleRouter from "@/router/modules/sample"
import residuesRouter from "@/router/modules/residues"
import fastRouter from "@/router/modules/fast"

export const constantRoutes = [
  // fastRouter,
  // {
  //   path: '/ordertem',
  //   component: () => import('@/views/order/orderPrint'),
  //   forget: true,
  //   hidden: true
  // },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
    forget: true,
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    forget: true,
    hidden: true
  },
  {
    path: '/bigdata',
    component: () => import('@/views/bigData/bigData.vue'),
    forget: true,
    hidden: true
  },
  //自己的
  {
    path: '/newBigdata',
    component: () => import('@/views/newBigData/newBigData.vue'),
    forget: true,
    hidden: true
  },
  //  大屏
  {
    path: '/screen',
    component: () => import('@/views/screen/index.vue'),
    forget: true,
    hidden: true
  },
  {
    path: '/demo',
    component: () => import('@/views/bigData/demo.vue'),
    forget: true,
    hidden: true
  },
  // 编辑通用模板
  // {
  //   path: '/print/ordertemplate',
  //   component: Layout,
  //   name: 'orderprint',
  //   component: () => import('@/views/global/print_order/Main'),
  //   forget: true,
  //   hidden: true
  // },
  // 新增模板
  {
    path: '/print/addOrderTemplate',
    component: Layout,
    name: 'addOrderPrint',
    component: () => import('@/views/global/add_print_order/Main'),
    forget: true,
    hidden: true
  },
  {
    path: '/print/sortnotetemplate',
    component: Layout,
    name: 'sortprint',
    component: () => import('@/views/global/print_sort_note/Main'),
    forget: true,
    hidden: true
  },
  {
    path: '/print/406',
    component: Layout,
    name: 'orderprint_copy',
    component: () => import('@/views/global/print_order_copy/Main'),
    forget: true,
    hidden: true
  },
  {
    path: '/commission/pay',
    name: 'commission_pay',
    component: () => import('@/views/index/commissionPay'),
    forget: true,
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    forget: true,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/index/index'),
        meta: { title: '首页', icon: 'index', noCache: true }
      },
      {
        path: '/moretender',
        name: 'moretender',
        component: () => import('@/views/index/components/moreTender.vue'),
        meta: { title: '招标信息', icon: 'index' }
      },
      {
        path: '/morefeedback',
        name: 'morefeedback',
        component: () => import('@/views/index/components/moreFeedBack.vue'),
        meta: { title: '更多反馈', icon: 'index' }
      }
    ]
  },
  merchantRouter,
  supplierRouter,
  relationRouter,
  traceability,
  priceRouter,
  orderRouter,
  {
    path: '/news/index',
    component: Layout,
    redirect: 'noRedirect',
    name: 'news',
    hidden: false,
    meta: {
      title: '新闻管理',
      abbre: '新闻',
      icon: 'left_menu_news',
      navigation: '/news/index',
      id: '407'
    },
    children: [
      {
        path: '/news/index',
        component: () => import('@/views/news/index'),
        name: 'newslist',
        hidden: false,
        meta: {
          title: '新闻列表',
          noCache: false,
          navigation: '/news/index',
          icon: 'menu_big_data'
        }
      }, {
        path: '/news/plus',
        component: () => import('@/views/news/newsplus'),
        name: 'newsplus',
        hidden: true,
        meta: {
          title: '增加新闻',
          bread: '增加新闻',
          noCache: true,
          navigation: '/news/index',
          icon: 'menu_big_data'
        }
      },
      {
        path: '/news/edit/:id',
        component: () => import('@/views/news/newsEdit'),
        name: 'newsedit',
        hidden: true,
        meta: {
          title: '修改新闻',
          bread: '修改新闻',
          noCache: true,
          navigation: '/news/index',
          icon: 'menu_big_data'
        }
      },
      {
        path: '/news/add',
        component: () => import('@/views/news/newsAdd'),
        name: 'newsadd',
        hidden: true,
        meta: {
          title: '新增新闻',
          bread: '新增新闻',
          noCache: true,
          navigation: '/news/index',
          icon: 'menu_big_data'
        }
      },
      {
        path: '/news/banner',
        component: () => import('@/views/news/banner/List'),
        name: 'bannerlist',
        hidden: false,
        meta: {
          title: '广告列表',
          noCache: false,
          navigation: '/news/banner',
          icon: 'menu_big_data'
        }
      },
      {
        path: '/news/sort',
        component: () => import('@/views/news/sortList'),
        name: 'sortlist',
        hidden: false,
        meta: {
          title: '分类列表',
          noCache: false,
          navigation: '/news/sort',
          icon: 'menu_big_data'
        }
      },
      {
        path: '/news/banneradd',
        component: () => import('@/views/news/banner/Add'),
        name: 'banneradd',
        hidden: true,
        meta: {
          title: '创建广告',
          bread: '创建广告',
          noCache: true,
          navigation: '/news/banner',
          icon: 'menu_big_data'
        }
      },
    ]
  },
  residuesRouter,
  menuRouter,
  sampleRouter,
  configuration,
  // warehouseRouter,
  // commodityRouter,
  // userRouter,
  // marketingRouter,
  // financialRouter,
  // reportRouter,
  // shopRouter,
  // // kitchenRouter,
  // distributionRouter,
  globalRouter,
  feedbackRouter,
  // tplusRouter,
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', forget: true, hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  window.location.reload()
  router.matcher = newRouter.matcher
}

export default router
